package logic

import (
	"context"
	"fmt"
	// "database/sql"

	"e4ting/internal/svc"
	"e4ting/internal/model"
	"e4ting/pb/e4ting"

	"github.com/zeromicro/go-zero/core/logx"
)

type NewAccountLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNewAccountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewAccountLogic {
	return &NewAccountLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *NewAccountLogic) NewAccount(in *e4ting.NewAccountReq) (*e4ting.OneAccountRes, error) {
	fmt.Printf("%+v\n", in)

	data := model.Moneys{
		Types : int64(in.TypeID),
		Uuid  : in.Uuid,
		Money  : 0,
		Name  : in.Name,
		Detail : in.Detail,
	}

	err := l.svcCtx.MoneyModel.Insert(l.ctx, &data)

	if err != nil {
		return &e4ting.OneAccountRes{
			Code: 400,
			Err: err.Error(),
		}, nil
	}
	data,_ = l.svcCtx.MoneyModel.FindOneByName(l.ctx, in.Name)
	return &e4ting.OneAccountRes{
		Code: 200,
		Data: ToAccountData(data),
	}, nil
}
